﻿@{
    ViewBag.Title = "日常巡检计划";
    Layout = "~/Views/Shared/PlanPartial/_LayoutDetail.cshtml";
}

@using Wicresoft.UnifyShow.Utility;
@using Wicresoft.UnifyShow.Business;

@{
    var serverTypes = ViewData["ServerType"] as EnumDataSource<EnumUtility.ServerType>;
    var Using = ViewData["Using"] as List<string>;
    var Vendor = ViewData["Vendor"] as List<string>;
    var Version = ViewData["Version"] as List<string>;
    var currentUser = ViewBag.CurrentUser as User_XModel;

    var dbVersion = ViewData["DBVersion"] as List<string>;
    var middleVersion = ViewData["MiddleVersion"] as List<string>;

    var Model = ViewData["Model"] as ScheduleJob;
    var isView = Model != null && Model.Job != null;
    var job = isView ? Model.Job : null;
    var jobDetail = (isView && job != null) ? job.JobDetail : "";

    //创建人可以编辑计划
    var canEdit = (isView && currentUser.ID == job.JobOwnerID) || !isView;
}


@section Name{巡检计划名称：}
@section Description{巡检计划描述：}
@section CycleTitle{巡检计划时间以及周期设置：}

@section Responsible{
    <div class="parameter">
        <div class="parameter_name">
            <span class="required">*</span>
            责任人：
        </div>
        <div class="parameter_input short">
            <input type="text" disabled="disabled" value="@(isView ? job.TaskUserName : "")" data-required-info="请选择责任人!" data-from="username" id="Responsible" />
            <input type="hidden" id="ResponsibleID" value="@(isView ? job.TaskUserID.ToString() : "")" data-model-source="TaskUserID" data-from="userid" />
            @if (canEdit)
            {
                <span class="icon-search" onclick="openResponsibleSearch();"></span>
            }
        </div>
    </div>
}

@section InspectionObject{
    <div class="parameter_name">
        添加巡检对象：
    </div>
    <div id="objectTabs" class="easyui-tabs" style="width: 820px; height: auto">
        <input type="hidden" id="jobDetail" value="@jobDetail" />
        <div title="业务系统" style="padding: 10px">
            <div class="padding5">
                <table id="BusinessSystems" class="" title="业务系统"
                    fitcolumns="true" singleselect="true" data-field="BusinessInsp">
                    <thead>
                        <tr>
                            <th field="AppSystemName" width="160">业务系统名称</th>
                            <th field="IPAddress" width="160">IP地址</th>
                            <th field="Ope" width="160">操作</th>
                        </tr>
                    </thead>
                </table>
                <div class="padding10 externalAdd">
                    <div class="parameter">
                        <div class="parameter_name">资产系统搜索：</div>
                        <div class="parameter_input" style="width: 450px;">
                            <input type="text" class="easyui-searchbox" data-options="prompt:'资金监管',searcher:InspObj.doBusinessSearch" />
                        </div>
                    </div>
                    <div class="parameter" style="padding-top: 10px;">
                        <div class="parameter_name">手工添加：</div>
                        <div class="parameter_input border_1 padding10 innerAdd" id="businessAddContainer">
                            <div class="parameter">
                                <div class="parameter_name" style="width: 120px;">业务系统名称：</div>
                                <div class="parameter_input" style="width: 300px;">
                                    <input type="text" data-source="AppSystemName" />
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 120px;">IP地址：</div>
                                <div class="parameter_input" style="width: 300px;">
                                    <input type="text" data-source="IPAddress" />
                                </div>
                            </div>
                            <div class="parameter" style="padding: 10px 0;">
                                <input type="button" value="添加" style="width: 85px; height: 30px;" onclick="InspObj.AddBusinessSys();" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div title="机房保障" style="padding: 10px" data-field="Environment">
            <div class="padding20">
                <input type="checkbox" id="AirConditioning" data-column="AirConditioning" />
                <label for="AirConditioning">精密空调</label>
            </div>
            <div class="padding20">
                <input type="checkbox" id="Temperature" data-column="Temperature" />
                <label for="Temperature">温度湿度</label>
            </div>
            <div class="padding20">
                <input type="checkbox" id="UPS" data-column="UPS" />
                <label for="UPS">UPS电源</label>
            </div>
        </div>
        <div title="服务器" style="padding: 10px">
            <div class="padding5">
                <table id="ServerSystem" class="" title="服务器"
                    fitcolumns="true" singleselect="true" data-field="ServerInsp">
                    <thead>
                        <tr>
                            <th field="DeviceName" width="120">主机名</th>
                            <th field="Item" width="120">机型</th>
                            <th field="IPAddress" width="120">IP地址</th>
                            <th field="Usaged" width="120">用途</th>
                            <th field="Ope" width="120">操作</th>
                        </tr>
                    </thead>
                </table>
                <div class="padding10 externalAdd">
                    <div class="parameter">
                        <div class="parameter_name">服务器搜索：</div>
                        <div class="parameter_input" style="width: 450px;">
                            <input type="text" class="easyui-searchbox" data-options="prompt:'主机名',searcher:InspObj.doServerSearch" />
                        </div>
                    </div>
                    <div class="parameter" style="padding-top: 10px;">
                        <div class="parameter_name">手工添加：</div>
                        <div class="parameter_input border_1 padding10 innerAdd" id="serverAddContainer">
                            <div class="parameter">
                                <div class="parameter_name" style="width: 57px;">主机名：</div>
                                <div class="parameter_input" style="width: 150px;">
                                    <input type="text" data-source="DeviceName" style="width: 80%;" />
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 57px;">机型：</div>
                                <div class="parameter_input" style="width: 150px;">
                                    <select data-source="Item" style="width: 120px;">
                                        @foreach (var item in serverTypes)
                                        {
                                            <option value="@(item.DisplayValue)">@(item.DisplayValue)</option>
                                        }
                                    </select>
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 57px;">IP地址：</div>
                                <div class="parameter_input" style="width: 150px;">
                                    <input type="text" data-source="IPAddress" style="width: 80%;" />
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 57px;">用途：</div>
                                <div class="parameter_input" style="width: 150px;">
                                    <select data-source="Usaged" style="width: 120px;" class="easyui-combobox">
                                        @foreach (var item in Using)
                                        {
                                            <option value="@item">@item</option>
                                        }
                                    </select>
                                </div>
                            </div>
                            <div class="parameter" style="padding: 10px 0;">
                                <input type="button" value="添加" style="width: 85px; height: 30px;" onclick="InspObj.AddServerSys();" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div title="网络设备" style="padding: 10px">
            <div class="padding5">
                <table id="NetSystem" class="" title="网络设备"
                    fitcolumns="true" singleselect="true" data-field="NetInsp">
                    <thead>
                        <tr>
                            <th field="DeviceName" width="120">设备名称</th>
                            <th field="ManufacturerName" width="120">品牌</th>
                            <th field="Model" width="120">型号</th>
                            <th field="IPAddress" width="120">管理IP</th>
                            <th field="Ope" width="120">操作</th>
                        </tr>
                    </thead>
                </table>
                <div class="padding10 externalAdd">
                    <div class="parameter">
                        <div class="parameter_name">网络设备搜索：</div>
                        <div class="parameter_input" style="width: 450px;">
                            <input type="text" class="easyui-searchbox" data-options="prompt:'设备名称',searcher:InspObj.doNetSearch" />
                        </div>
                    </div>
                    <div class="parameter" style="padding-top: 10px;">
                        <div class="parameter_name">手工添加：</div>
                        <div class="parameter_input border_1 padding10 innerAdd" id="netAddContainer">
                            <div class="parameter">
                                <div class="parameter_name" style="width: 70px;">设备名称：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <input type="text" data-source="DeviceName" style="width: 90%;" />
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 70px;">品牌：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <select data-source="ManufacturerName" style="width: 93%;">
                                        @foreach (var item in Vendor)
                                        { 
                                            <option value="@(item)">@item</option>
                                        }
                                    </select>
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 70px;">型号：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <input type="text" data-source="Model" style="width: 90%;" />
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 70px;">管理IP：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <input type="text" data-source="IPAddress" style="width: 90%;" />
                                </div>
                            </div>

                            <div class="parameter" style="padding: 10px 0;">
                                <input type="button" value="添加" style="width: 85px; height: 30px;" onclick="InspObj.AddNetSys();" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div title="安全设备" style="padding: 10px">
            <div class="padding5">
                <table id="SafetyEquipment" class="" title="安全设备"
                    fitcolumns="true" singleselect="true" data-field="SafetyInsp">
                    <thead>
                        <tr>
                            <th field="DeviceName" width="120">设备名称</th>
                            <th field="ManufacturerName" width="120">品牌</th>
                            <th field="Model" width="120">型号</th>
                            <th field="IPAddress" width="120">管理IP</th>
                            <th field="Ope" width="120">操作</th>
                        </tr>
                    </thead>
                </table>
                <div class="padding10 externalAdd">
                    <div class="parameter">
                        <div class="parameter_name">安全设备搜索：</div>
                        <div class="parameter_input" style="width: 450px;">
                            <input type="text" class="easyui-searchbox" data-options="prompt:'设备名称',searcher:InspObj.doSafetySearch" />
                        </div>
                    </div>
                    <div class="parameter" style="padding-top: 10px;">
                        <div class="parameter_name">手工添加：</div>
                        <div class="parameter_input border_1 padding10 innerAdd" id="safetyAddContainer">
                            <div class="parameter">
                                <div class="parameter_name" style="width: 70px;">设备名称：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <input type="text" data-source="DeviceName" style="width: 90%;" />
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 70px;">品牌：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <select data-source="ManufacturerName" style="width: 93%;">
                                        @foreach (var item in Vendor)
                                        { 
                                            <option value="@(item)">@item</option>
                                        }
                                    </select>
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 70px;">型号：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <input type="text" data-source="Model" style="width: 90%;" />
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 70px;">管理IP：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <input type="text" data-source="IPAddress" style="width: 90%;" />
                                </div>
                            </div>
                            <div class="parameter" style="padding: 10px 0;">
                                <input type="button" value="添加" style="width: 85px; height: 30px;" onclick="InspObj.AddSafetyEqui();" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div title="数据库" style="padding: 10px">
            <div class="padding5">
                <table id="DatabaseSys" class="" title="数据库"
                    fitcolumns="true" singleselect="true" data-field="DBInsp">
                    <thead>
                        <tr>
                            <th field="DbAndVersion" width="120">数据库版本</th>
                            <th field="IPAddress" width="120">IP地址</th>
                            <th field="Usaged" width="120">用途</th>
                            <th field="Ope" width="120">操作</th>
                        </tr>
                    </thead>
                </table>
                <div class="padding10 externalAdd">
                    <div class="parameter">
                        <div class="parameter_name">数据库搜索：</div>
                        <div class="parameter_input" style="width: 450px;">
                            <input type="text" class="easyui-searchbox" data-options="prompt:'IP地址',searcher:InspObj.doDBSearch" />
                        </div>
                    </div>
                    <div class="parameter" style="padding-top: 10px;">
                        <div class="parameter_name">手工添加：</div>
                        <div class="parameter_input border_1 padding10 innerAdd" id="dbAddContainer">
                            <div class="parameter">
                                <div class="parameter_name" style="width: 85px;">数据库版本：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <select data-source="DbAndVersion" style="width: 125px;">
                                        @foreach (var item in dbVersion)
                                        {
                                            <option value="@item">@item</option>
                                        }
                                    </select>
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 85px;">用途：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <select data-source="Usaged" style="width: 125px;" class="easyui-combobox">
                                        @foreach (var item in Using)
                                        {
                                            <option value="@item">@item</option>
                                        }
                                    </select>
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 85px;">管理IP：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <input type="text" data-source="IPAddress" style="width: 90%;" />
                                </div>
                            </div>
                            <div class="parameter">
                                <input type="button" value="添加" style="width: 85px; height: 30px;" onclick="InspObj.AddDBSystem();" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div title="中间件" style="padding: 10px">
            <div class="padding5">
                <table id="MiddlewareSys" class="" title="中间件"
                    fitcolumns="true" singleselect="true" data-field="MiddleWareInsp">
                    <thead>
                        <tr>
                            <th field="MidAndVersion" width="120">中间件版本</th>
                            <th field="IPAddress" width="120">IP地址</th>
                            <th field="Usaged" width="120">用途</th>
                            <th field="Ope" width="120">操作</th>
                        </tr>
                    </thead>
                </table>
                <div class="padding10 externalAdd">
                    <div class="parameter">
                        <div class="parameter_name">中间件搜索：</div>
                        <div class="parameter_input" style="width: 450px;">
                            <input type="text" class="easyui-searchbox" data-options="prompt:'IP地址',searcher:InspObj.doMiddlewareSearch" />
                        </div>
                    </div>
                    <div class="parameter" style="padding-top: 10px;">
                        <div class="parameter_name">手工添加：</div>
                        <div class="parameter_input border_1 padding10 innerAdd" id="middlewareAddContainer">
                            <div class="parameter">
                                <div class="parameter_name" style="width: 85px;">中间件版本：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <select data-source="MidAndVersion" style="width: 125px;">
                                        @foreach (var item in middleVersion)
                                        {
                                            <option value="@item">@item</option>
                                        }
                                    </select>
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 85px;">用途：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <select data-source="Usaged" style="width: 125px;" class="easyui-combobox">
                                        @foreach (var item in Using)
                                        {
                                            <option value="@item">@item</option>
                                        }
                                    </select>
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 85px;">管理IP：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <input type="text" data-source="IPAddress" style="width: 90%;" />
                                </div>
                            </div>
                            <div class="parameter">
                                <input type="button" value="添加" style="width: 85px; height: 30px;" onclick="InspObj.AddMiddlewareSystem();" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div title="存储" style="padding: 10px">
            <div class="padding5">
                <table id="StorageSys" class="" title="存储"
                    fitcolumns="true" singleselect="true" data-field="StorageInsp">
                    <thead>
                        <tr>
                            <th field="Model" width="120">存储型号</th>
                            <th field="IPAddress" width="120">管理IP地址</th>
                            <th field="Ope" width="120">操作</th>
                        </tr>
                    </thead>
                </table>
                <div class="padding10 externalAdd">
                    <div class="parameter">
                        <div class="parameter_name">存储搜索：</div>
                        <div class="parameter_input" style="width: 450px;">
                            <input type="text" class="easyui-searchbox" data-options="prompt:'IP地址',searcher:InspObj.doStorageSearch" />
                        </div>
                    </div>
                    <div class="parameter" style="padding-top: 10px;">
                        <div class="parameter_name">手工添加：</div>
                        <div class="parameter_input border_1 padding10 innerAdd" id="storageAddContainer">
                            <div class="parameter">
                                <div class="parameter_name" style="width: 85px;">存储型号：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <input type="text" data-source="Model" style="width: 90%;" />
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 85px;">管理IP：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <input type="text" data-source="IPAddress" style="width: 90%;" />
                                </div>
                            </div>
                            <div class="parameter">
                                <input type="button" value="添加" style="width: 85px; height: 30px;" onclick="InspObj.AddStorageSystem();" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div title="备份" style="padding: 10px">
            <div class="padding5">
                <table id="BackupSys" class="" title="备份"
                    fitcolumns="true" singleselect="true" data-field="BackupInsp">
                    <thead>
                        <tr>
                            <th field="DbAndVersion" width="120">数据库版本</th>
                            <th field="IPAddress" width="120">IP地址</th>
                            <th field="Usaged" width="120">用途</th>
                            <th field="Ope" width="120">操作</th>
                        </tr>
                    </thead>
                </table>
                <div class="padding10 externalAdd">
                    <div class="parameter">
                        <div class="parameter_name">数据库搜索：</div>
                        <div class="parameter_input" style="width: 450px;">
                            <input type="text" class="easyui-searchbox" data-options="prompt:'IP地址',searcher:InspObj.doBackupSearch" />
                        </div>
                    </div>
                    <div class="parameter" style="padding-top: 10px;">
                        <div class="parameter_name">手工添加：</div>
                        <div class="parameter_input border_1 padding10 innerAdd" id="backupAddContainer">
                            <div class="parameter">
                                <div class="parameter_name" style="width: 85px;">数据库版本：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <select data-source="DbAndVersion" style="width: 125px;">
                                        @foreach (var item in dbVersion)
                                        {
                                            <option value="@item">@item</option>
                                        }
                                    </select>
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 85px;">用途：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <select data-source="Usaged" style="width: 125px;" class="easyui-combobox">
                                        @foreach (var item in Using)
                                        {
                                            <option value="@item">@item</option>
                                        }
                                    </select>
                                </div>
                            </div>
                            <div class="parameter">
                                <div class="parameter_name" style="width: 85px;">管理IP：</div>
                                <div class="parameter_input" style="width: 135px;">
                                    <input type="text" data-source="IPAddress" style="width: 90%;" />
                                </div>
                            </div>
                            <div class="parameter">
                                <input type="button" value="添加" style="width: 85px; height: 30px;" onclick="InspObj.AddBackupSystem();" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

}

@if (!canEdit)
{ 
    <script type="text/javascript">
        $(function () {
            //isView时隐藏巡检对象的手动添加区域
            $('.externalAdd').hide();
        });
    </script>
}

<script type="text/javascript">


    //保存机房日常巡检
    var SavePlan = function () {
        var data = {};

        data["JobType"] = 1;

        var inspObj = InspObj.GetAllObj();
        data["JobDetail"] = JSON.stringify(inspObj);

        planSave(data);
    };

    //解析json巡检对象
    var setInspectionDetail = function () {
        var detail = $('#jobDetail').val();
        if (detail) {
            var detailObj = JSON.parse(detail);
            $.each(detailObj, function (fieldName, data) {
                if ($('[data-field="' + fieldName + '"]').length) {
                    if (fieldName == "Environment") {
                        $.each(data, function (columnName, check) {
                            if (check == true) {
                                $('[data-column="' + columnName + '"]').attr('checked', true);
                            }
                        });
                    } else {
                        var canEdit = $('#canEdit').val() == "True";
                        if (canEdit) {
                            $.each(data, function (i, _data) {
                                _data["Ope"] = '<a class="deleteRow">删除</a>';
                            });
                        }
                        $('[data-field="' + fieldName + '"]').datagrid({
                            data: data
                        });
                    }
                }
            });
        }
    };


    $(function () {

        $('#objectTabs').tabs({ tabPosition: 'left' });

        InspObj.RegisterGrid("BusinessSystems");

        InspObj.RegisterGrid("ServerSystem");

        InspObj.RegisterGrid("NetSystem");

        InspObj.RegisterGrid("SafetyEquipment");

        InspObj.RegisterGrid("DatabaseSys");

        InspObj.RegisterGrid("MiddlewareSys");

        InspObj.RegisterGrid("StorageSys");

        InspObj.RegisterGrid("BackupSys");

        setInspectionDetail();

        var canEdit = $('#canEdit').val() == "True";
        if (canEdit) {
            window.setTimeout(function () {
                enableControl('objectTabs');
                $('.easyui-combobox').combobox('enable');
            }, 0);
        }

    });
</script>
